import React, { Component } from 'react'
import axios from 'axios'
import Fenye from './fenye'
class New extends Component {
  state = {
      arr:[],
      index:1 // 默认第一页
  }
  componentDidMount(){
      axios.get("/list").then(res=>{
          console.log(res.data);
          this.setState({
              arr:res.data
          })
      })
  }
  checkfenye = (data)=>{
        this.setState({
            index:data
        })
  }
  render() {
      let {arr,index} = this.state
      let list = arr.slice((index-1)*5,index*5)
      console.log(list);
    return (
      <div>
          {
              list&&list.length?list.map((item,index)=>{
                  return <div key={index}>{item.name1}</div>
              }):"暂无数据"
          }
          {/* activeIndex 将第几页传给分页组件，用于分页组件点击高亮 */}
         <Fenye sendfn={this.checkfenye} activeIndex={this.state.index}></Fenye>
      </div>
    )
  }
}

export default New